home *** CD-ROM | disk | FTP | other *** search
/ E.M.Computergraphic Phase 4 / Phase 4 - Desktop Video Dreams (E. M. Computergraphic)(1996).iso / utilities / imagestudio / rexx / convolvetest.isrx < prev    next >
Text File  |  1996-01-17  |  4KB  |  181 lines

  1. /* ImageStudio ARexx script **************************************/
  2.  
  3. /* Allow commands to return results */
  4.  
  5. options results
  6.  
  7. /* On error, goto ERROR:. Comment out this line if you wish to */
  8. /* perform your own error checking. */
  9.  
  10. signal on error
  11.  
  12. /* BEGIN PROGRAM *************************************************/
  13.  
  14. /* See if we have an image already */
  15.  
  16. IMAGEINFO_GET STEM imageinfo.
  17.  
  18. if imageinfo.changed == 1 then do
  19.     REQUEST_MESSAGE TEXT '"Project has changed, continue?"',
  20.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  21.  
  22.     end
  23. else if imageinfo.changed == -1 then do
  24.     /* Open a filerequester to get an image to operate on */
  25.  
  26.     REQUEST_FILE TITLE '"Choose image..."' VAR imagefile
  27.  
  28.     OPEN FILE '"'imagefile'"'
  29.  
  30.     /* Get the new image's details */
  31.  
  32.     IMAGEINFO_GET STEM 'imageinfo.'
  33.  
  34.     end
  35.  
  36. /* Choose the convoluion filters to apply */
  37.  
  38. PREF_GET NAME 'CONVOLVEDIR' VAR convolvedir
  39.  
  40. REQUEST_MULTIFILE PATHPART '"'convolvedir'"' TITLE '"Select filters..."',
  41.     STEM convolves.
  42.  
  43. /* Work out how we should tile the image (could do this with a */
  44. /* square root, but we don't have the maths libraries loaded). */
  45. /* This is also not a particularly smart tiling algorithm, but */
  46. /* we're not trying to demonstrate "particularly smart tiling */
  47. /* algorithm"s :-) */
  48.  
  49. /* Block GUI, selection may take some time */
  50.  
  51. GUI_BLOCK
  52.  
  53. num_files = convolves.files.count
  54.  
  55. select
  56.     when convolves.files.count == 1 then
  57.         num_tiles = 1
  58.     when convolves.files.count <= 4 then
  59.         num_tiles = 2
  60.     when convolves.files.count <= 9 then
  61.         num_tiles = 3
  62.     when convolves.files.count <= 16 then
  63.         num_tiles = 4
  64.     when convolves.files.count <= 25 then
  65.         num_tiles = 5
  66.     when convolves.files.count <= 36 then
  67.         num_tiles = 6
  68.     when convolves.files.count <= 49 then
  69.         num_tiles = 7
  70.     when convolves.files.count <= 64 then
  71.         num_tiles = 8
  72.     when convolves.files.count <= 81 then
  73.         num_tiles = 9
  74.     otherwise do
  75.         num_tiles = 10
  76.  
  77.         num_files = 100
  78.  
  79.         end
  80.     end
  81.  
  82. GUI_UNBLOCK
  83.  
  84. /* If the image is colour mapped, change it to 24bit */
  85.  
  86. if imageinfo.depth ~= 24 then
  87.     COLOURS SIXTEENMILLION
  88.  
  89. /* Loop through all the files */
  90.  
  91. do l = 0 to num_files - 1
  92.     /* Work out region to select */
  93.  
  94.     xtile = l // num_tiles
  95.     ytile = l % num_tiles 
  96.     
  97.     left = (xtile * imageinfo.width) % num_tiles
  98.     right = (((xtile + 1) * imageinfo.width) % num_tiles - 1)
  99.  
  100.     top = (ytile * imageinfo.height) % num_tiles
  101.     bottom = (((ytile + 1) * imageinfo.height) % num_tiles - 1)
  102.  
  103.     /* Select the region */
  104.  
  105.     REGION_SET left top TO right bottom
  106.  
  107.     /* Get the name of the filter */
  108.  
  109.     FILE_SPLIT FILE '"'convolves.files.l'"' STEM 'fileinfo.'
  110.  
  111.     /* Apply a filter on that region */
  112.  
  113.     CONVOLVE NAME '"'fileinfo.filepart'"'
  114.  
  115.     end
  116.  
  117. /* Clear the region */
  118.  
  119. REGION_CLEAR
  120.  
  121. /* END PROGRAM ***************************************************/
  122.  
  123. exit
  124.  
  125. /* On ERROR */
  126.  
  127. ERROR:
  128.  
  129. /* If we get here, either an error occurred with the command's */
  130. /* execution or there was an error with the command itself. */
  131. /* In the former case, rc2 contains the error message and in */
  132. /* the latter, rc2 contains an error number. SIGL contains */
  133. /* the line number of the command which caused the jump */
  134. /* to ERROR: */
  135.  
  136. if datatype(rc2,'NUMERIC') == 1 then do
  137.     /* See if we can describe the error with a string */
  138.  
  139.     select
  140.         when rc2 == 103 then
  141.             err_string = "ERROR 103, "||,
  142.                 "out of memory at line "||SIGL
  143.         when rc2 == 114 then
  144.             err_string = "ERROR 114, "||,
  145.                 "bad command template at line "||SIGL
  146.         when rc2 == 115 then
  147.             err_string = "ERROR 115, "||,
  148.                 "bad number for /N argument at line "||SIGL
  149.         when rc2 == 116 then
  150.             err_string = "ERROR 116, "||,
  151.                 "required argument missing at line "||SIGL
  152.         when rc2 == 117 then
  153.             err_string = "ERROR 117, "||,
  154.                 "value after keywork missing at line "||SIGL
  155.         when rc2 == 118 then
  156.             err_string = "ERROR 118, "||,
  157.                 "wrong number of arguments at line "||SIGL
  158.         when rc2 == 119 then
  159.             err_string = "ERROR 119, "||,
  160.                 "unmatched quotes at line "||SIGL
  161.         when rc2 == 120 then
  162.             err_string = "ERROR 120, "||,
  163.                 "line too long at line "||SIGL
  164.         when rc2 == 236 then
  165.             err_string = "ERROR 236, "||,
  166.                 "unknown command at line "||SIGL
  167.         otherwise
  168.             err_string = "ERROR "||rc2||", at line "||SIGL
  169.         end
  170.         end
  171. else if rc2 == 'RC2' then do
  172.     err_string = "ERROR in command at line "||SIGL
  173.     end
  174. else do
  175.         err_string = rc2||", line "||SIGL
  176.         end
  177.  
  178. request_message TEXT '"'err_string'"'
  179.  
  180. exit
  181.